package com.itheima.mapper;

import com.itheima.pojo.Dish;
import com.itheima.pojo.Setmeal;
import com.itheima.pojo.SetmealPage;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 统计页面数量
     */
    @Select("select count(*) from setmeal")
    int count();
    /**
     * 套餐分页查询
     */
    List<SetmealPage> pageQuery(String name, Integer page, Integer pageSize);

    /**
     * 删除套餐
     */
    @Delete(" delete setmeal ,setmealdishes  from setmeal left join setmealdishes on setmeal.id = setmealdishes.setmealId where setmeal.id=#{id};")
    int delet (String id);

    /**
     * 新增套餐
     */
    @Insert("insert into setmeal(id,name,categoryId,price,code,image,description,status,idtype)values (#{id},#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{idtype})")
    int addSetmeal(Setmeal setmeal);

    /**
     * 根据id获取Setmeal对象使用
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal selectById(String id);

    /**
     * 根据id获取套餐
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal selectSetmeal(String id);

    /**
     * 修改套餐
     */
    int updeteSetmeal(Setmeal setmeal);

    /**
     * 套餐上架/下架
     */
    int updatestatus(String id,Integer status);


    /**
     *  套餐列表
     */
    @Select("select id,type,categoryId,name,price,status,code,description,image from setmeal where categoryId=#{categoryId}and status=#{status}")
    List<Setmeal>selectDetails(String categoryId,Integer status);
}
